package com.ruoqing.log.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoqing.core.domain.rqlog.LogEntity;
import com.ruoqing.log.dao.BaseLogDao;
import com.ruoqing.log.service.BaseLogService;
import com.ruoqing.utils.common.ObjectUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
	* @author YaoXian
	* @title: BaseLogServiceImpl
	* @projectName ruoxi-blog
	* @description: 若兮微服务 -
	* @date 2020-12-07 16:54
	*/
@Slf4j
@Service
public class BaseLogServiceImpl implements BaseLogService {
		
		@Resource
		private BaseLogDao baseLogDao;
		
		public void saveBaseLog(LogEntity logEntity) {
				if (ObjectUtils.isNotNull(logEntity)){
						baseLogDao.insert(logEntity);
				}else {
						log.error("日志收集异常,参数为空!");
				}
		}
		
		public Page<LogEntity> selectLogByPage(Integer currentPage, Integer pageSize) {
				QueryWrapper<LogEntity> queryWrapper = new QueryWrapper<LogEntity>();
				Page<LogEntity> page = new Page<LogEntity>(currentPage, pageSize);
				return baseLogDao.selectPage(page,queryWrapper);
		}
		
		@Transactional(rollbackFor = Exception.class)
		public Integer deleteBaseLog(Integer logId) {
				return baseLogDao.deleteById(logId);
		}
}
